/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package goodenglish.interfaces.videoplay;

import javafx.util.Duration;

/**
 *
 * @author 关攀攀 panpan_001@126.com
 */
public class DurationHelper {

    /**
     * 根据已播放时间和总时间的Duration对象得到字符串显示
     *
     * @param elapsed 已播放时间
     * @param duration 总时间
     * @return
     */
    public static String formatTime(Duration elapsed, Duration duration) {
        DurationTime elapsedTime = new DurationTime(elapsed);


        if (duration.greaterThan(Duration.ZERO)) {
            DurationTime durationTime = new DurationTime(duration);
            int intDuration = (int) Math.floor(duration.toSeconds());

            if (durationTime.hours > 0) {
                return String.format("%d:%02d:%02d/%d:%02d:%02d",
                        elapsedTime.hours, elapsedTime.minutes, elapsedTime.seconds,
                        durationTime.hours, durationTime.minutes, durationTime.seconds);
            } else {
                return String.format("%02d:%02d/%02d:%02d",
                        elapsedTime.minutes, elapsedTime.seconds,
                        durationTime.minutes, durationTime.seconds);
            }
        } else {
            if (elapsedTime.hours > 0) {
                return String.format("%d:%02d:%02d",
                        elapsedTime.hours, elapsedTime.minutes, elapsedTime.seconds);
            } else {
                return String.format("%02d:%02d",
                        elapsedTime.minutes, elapsedTime.seconds);
            }
        }
    }
}
